import java.util.HashMap;

public abstract class Flyweight {
    public static void main(String[] args) {
        Flyweight fa1 = FlyweightFactory.getFlyweight("A");
        Flyweight fa2 = FlyweightFactory.getFlyweight("A");
        Flyweight fb1 = FlyweightFactory.getFlyweight("B");
        System.out.println(fa1 == fa2);
    }
}

class FlyweightA extends Flyweight {
}

class FlyweightB extends Flyweight {
}

class FlyweightFactory {
    static HashMap<String, Flyweight> kvs = new HashMap<String, Flyweight>();
    static {
        kvs.put("A", new FlyweightA());
        kvs.put("B", new FlyweightB());
    };

    public static Flyweight getFlyweight(String key) {
        return kvs.get(key);
    }
}